#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
struct ListNode {
    int val;
    struct ListNode* next;
};
int main()
{
	int count = 1;
	struct ListNode* s1 = (struct ListNode*)malloc(sizeof(struct ListNode));
	if (s1 == NULL)
	{
		perror("malloc");
		return 1;
	}
	struct ListNode* s2 = (struct ListNode*)malloc(sizeof(struct ListNode));
	if (s2 == NULL)
	{
		perror("malloc");
		return 1;
	}
	struct ListNode* s3 = (struct ListNode*)malloc(sizeof(struct ListNode));
	if (s3 == NULL)
	{
		perror("malloc");
		return 1;
	}
	struct ListNode* s4 = (struct ListNode*)malloc(sizeof(struct ListNode));
	if (s4 == NULL)
	{
		perror("malloc");
		return 1;
	}
	struct ListNode* s5 = (struct ListNode*)malloc(sizeof(struct ListNode));
	if (s5 == NULL)
	{
		perror("malloc");
		return 1;
	}
	s1->val = 1;
	s2->val = 2;
	s3->val = 3;
	s4->val = 4;
	s5->val = 5;
	s1->next = s2;
	s2->next = s3;
	s3->next = s4;
	s4->next = s5;
	s5->next = s1;
	struct ListNode* pcur = s1;
	struct ListNode* prev = s5;
	while (pcur->next != pcur)
	{
		if (count == 2)
		{
			prev->next = pcur->next;
			free(pcur);
			pcur = prev->next;
			count = 1;
		}
		else
		{
			prev = prev->next;
			pcur = pcur->next;
			count++;
		}
	}
	printf("%d", pcur->val);
	free(pcur);
	pcur = NULL;
	return 0;
}